
package com.example.cia.database.mysql.dao.impl;

import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.example.cia.database.mysql.dao.IQueryForInfo;
import com.mysql.jdbc.Connection;


public class queryDeviceInfo extends mysqlDaoImpl implements IQueryForInfo {
	
	String id;
	
	//获取一行详细信息
	@Override
	public List<String> getInfo(String id) throws ClassNotFoundException, SQLException, IOException {
		this.id = id;
		return query();
	}
	
	//修改获取表名
	@Override
	public String getTableName(){
		return "device";
	}

	//查询一行详细信息，将查询信息按顺序存储
	@Override
	public List<String> query() throws ClassNotFoundException, SQLException, IOException {
		String sql = "SELECT "+getQueryFieldString(0)+" FROM "
	             +getQulifiedTableName()+" WHERE "+getPrimaryKey()+" = ?";
		databaseManager db = databaseManager.createInstance();
		Connection con = db.getCon();
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setString(1, id);
		ResultSet rs = ps.executeQuery();
		List<String> result = new ArrayList<String>();
		rs.next();
		result.add(rs.getString(1));
		result.add(rs.getString(2));
		result.add(String.valueOf(rs.getInt(3)));
		rs.close();
		con.close();
		return result;
	}

}
